package com.dhy.domain;

import com.dhy.listener.RouteFailListener;
import com.dhy.util.RabbitmqUtil;
import com.rabbitmq.client.*;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.TimeoutException;

import static com.dhy.constants.RabbitmqConstants.*;
import static com.rabbitmq.client.BuiltinExchangeType.DIRECT;
import static com.rabbitmq.client.BuiltinExchangeType.TOPIC;

/**
 * @author 大忽悠
 * @create 2022/5/19 18:50
 */
@Slf4j
public class Publisher implements Runnable {
    @Override
    public void run() {
        try {
            RabbitmqUtil rabbitmqUtil = new RabbitmqUtil("application.yml");
            Channel channel = rabbitmqUtil.createChannel();
            //生成一个临时队列
            String queue = channel.queueDeclare().getQueue();
            AMQP.BasicProperties basicProperties = new AMQP.BasicProperties.Builder()
                    //指明回调队列的地址
                    .replyTo(queue).build();
            channel.basicPublish("","rpc_queue",basicProperties,"rpc调用".getBytes(StandardCharsets.UTF_8));
        } catch (IOException | TimeoutException e  ) {
            log.error("出现异常: ",e);
        }
    }
}
